/**
 * 
 */
package com.googlecode.bestpaper.output.pdf.book;

import java.awt.Color;

import com.googlecode.bestpaper.output.pdf.PDFHelper;
import com.googlecode.bestpaper.syntax.book.BPChapter;
import com.lowagie.text.Chapter;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Section;

/**
 * @author xalinx at gmail dot com
 * @date Dec 3, 2009
 */
public class PDFChapter extends BPChapter<Document, Section> {

	private int chapterNumber;

	private Color titleFontColor = new Color(0, 0, 0);

	private int titleFontStyle = Font.BOLD;

	public int getChapterNumber() {
		return chapterNumber;
	}

	public void setChapterNumber(int chapterNumber) {
		this.chapterNumber = chapterNumber;
	}

	public Color getTitleFontColor() {
		return titleFontColor;
	}

	public void setTitleFontColor(Color titleFontColor) {
		this.titleFontColor = titleFontColor;
	}

	public int getTitleFontStyle() {
		return titleFontStyle;
	}

	public void setTitleFontStyle(int titleFontStyle) {
		this.titleFontStyle = titleFontStyle;
	}

	@Override
	public int getTitleFontSize() {
		return 24;
	}

	/**
	 * @param title
	 */
	public PDFChapter(String title, int chapterNumber) {
		super(title);
		this.chapterNumber = chapterNumber;
	}

	public PDFChapter(int chapterNumber) {
		this(null, chapterNumber);
	}

	public PDFChapter() {

	}

	public Section buildSelf(Document document) throws Exception {
		Font titleFont = PDFHelper.getCNFont(getTitleFontSize(),
				titleFontStyle, titleFontColor);
		Paragraph title = new Paragraph(getTitle(), titleFont);
		Chapter chapter = new Chapter(title, chapterNumber);
		return chapter;
	}

	@Override
	public void build(Document writer, int fontStyle) throws Exception {
		Section chapter = buildSelf(writer);
		this.buildComponents(chapter, fontStyle);
		writer.add(chapter);
	}

}
